package jwxx.server;

import java.sql.ResultSet;
import java.sql.SQLException;


	public class RegisterSql {
		private ResultSet rs;
		private ResultSet rs_reg;
		public SAttribute search(String name)throws SQLException{
			String sql3 = "select * from attribute_table where name='"+name+"'";	
			String sql4 = "select MAX(id) AS id from attribute_table";	
			DbOperator db2 = new DbOperator();		
			SAttribute newplay=new SAttribute();
			SAttribute playreg=new SAttribute();
			SAttribute playreg2=new SAttribute();

			try{
				rs = db2.executeQuery(sql3, new Object[]{});
				while(rs.next()){
					newplay.setID(rs.getInt("id"));
					newplay.setSign(rs.getString("sign"));
					newplay.setNickName(rs.getString("nickname"));
					newplay.setLocalX(rs.getInt("local_position_x"));
					newplay.setLocalY(rs.getInt("local_position_y"));
					newplay.setName(rs.getString("name"));
					newplay.setSex(rs.getBoolean("sex"));				
					newplay.setPicID(rs.getInt("pic_id"));		
					newplay.setAccount(true);
				}
			}catch(SQLException e){
				e.printStackTrace();
			}		
			if(!newplay.getAccount())
			{
				DbOperator db3 = new DbOperator();
				newplay.setAccount(false);
				SAttributeSql reginster=new SAttributeSql();
				rs_reg = db3.executeQuery(sql4, new Object[]{});
				while(rs_reg.next()){
					playreg.setID(rs_reg.getInt("id"));
				}				
				playreg2.setID(playreg.getID()+1);
				playreg2.setName(name);
				reginster.insert(playreg2);		
				db3.close();
			}
			db2.close();
			return newplay;
		}	

	
}
